/**
 * 根据值查找树路径
 * @param {Array} tree 树结构
 * @param {string} targetValue 目标值
 * @param {Array} path 路径
 * @returns {Array} 路径
 */
export function findPathByValue(
  tree,
  targetValue,
  path = []
) {
  for (const node of tree) {
    const currentPath = [...path, node.deptName]

    if (node.deptName === targetValue) {
      return currentPath
    }

    if (node.childTree) {
      const result = findPathByValue(
        node.childTree,
        targetValue,
        currentPath
      )
      if (result) return result
    }
  }
  return null
}
